package com.bana.fvs.app.mvp.presenter;

import android.app.Activity;

import com.bana.fvs.app.module.detaile.entity.AreaControllerDetailBean;
import com.bana.fvs.app.module.detaile.entity.FoglightDetailInfo;
import com.bana.fvs.app.module.tab2.entity.ControlResultBean;
import com.bana.fvs.app.mvp.contract.FogLampListContract;
import com.bana.fvs.app.mvp.model.FogLampModel;
import com.wei.commonlibrary.net.CommException;
import com.wei.commonlibrary.net.MyDefaultCallback;

import java.util.List;

/**
 * Created by wei on 2018/4/1.
 */

public class FogLampPresenter extends FogLampListContract.AbsFoglightPresenter {
    @Override
    protected FogLampListContract.AbsFogLampModel createModel() {
        return new FogLampModel();
    }

    @Override
    public void getFogLampList(Activity activity, String token, String kzqbm, int pagenum) {
        mModel.getFogLampList(token, kzqbm, pagenum, 20)
                .callback(new MyDefaultCallback<AreaControllerDetailBean>(activity, true) {
                    @Override
                    public void onError(CommException e) {
                        if (getView() != null) {
                            getView().onError(e);
                        }
                    }

                    @Override
                    public void response(AreaControllerDetailBean foglightDetailInfos) {
                        if (getView() != null&&foglightDetailInfos!=null) {
                            getView().onResponse(foglightDetailInfos.getLamps());
                        }
                    }
                });
    }


    @Override
    public void http_controlLamp(Activity activity, String token, String sbbm, String kzcz) {
        mModel.http_controlLamp(token, sbbm, kzcz).callback(new MyDefaultCallback<ControlResultBean>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView())
                    getView().onError(e);
            }

            @Override
            public void response(ControlResultBean bean) {
                if (null != getView()) {
                    getView().onControllerResult(bean);
                }
            }
        });
    }

}
